﻿using System;
using System.IO;
using System.Xml.Serialization;

namespace CommunityServerRest {

	public class BlogPost {


		[XmlAttribute("Id")]
		public int Id { get; set; }

		[XmlAttribute("Endpoint")]
		public string Endpoint { get; set; }


		[XmlElement("Name")]
		public string Name { get; set; }

		[XmlElement("Title")]
		public string Title { get; set; }

		[XmlElement("Body")]
		public string Body { get; set; }

		[XmlElement("Date")]
		public DateTime Date { get; set; }

		[XmlElement("Settings")]
		public BlogPostSettings Settings { get; set; }

		[XmlElement("Keywords")]
		public Keywords Keywords { get; set; }

		[XmlElement("ViewCount")]
		public int Views { get; set; }


		public BlogInfo BlogInfo { get; set; }

		public AttachmentInfo AttachmentInfo { get; set; }

		public BlogPost() {
		}
	
		public static BlogPost Deserialize(Stream s) {
			XmlSerializer serializer = new XmlSerializer(typeof(BlogPost));
			StreamReader reader = new StreamReader(s);
			BlogPost post = (BlogPost)serializer.Deserialize(reader);

			reader.Close();
			return post;
		}

		internal void Serialize(Stream stream) {
			XmlSerializer serializer = new XmlSerializer(typeof(BlogPost));
			serializer.Serialize(stream, this);
		}

		public override string ToString() {
			return Id + ">" + Title;
		}
	}
}
